package pl.gigiel.behaviour.steer;

import pl.gigiel.behaviour.IBoid;
import pl.gigiel.behaviour.ISteer;
import pl.gigiel.behaviour.exception.BehaviourException;
import pl.gigiel.behaviour.util.Util;

import com.jme.math.Quaternion;
import com.jme.math.Vector3f;

public class WanderSteer implements ISteer {
	private static ISteer steer;
	private float amplitudeMin = -0.05f;
	private float amplitudeMax = 0.05f;

	private WanderSteer() {
		amplitudeMin = -0.05f;
		amplitudeMax = 0.05f;
	}

	public static ISteer getInstance() {
		if (steer == null) {
			steer = new WanderSteer();
		}
		return steer;
	}

	@Override
	public void init() throws BehaviourException {
		// nothing
	}

	@Override
	public Vector3f force(IBoid boid, float elapsed) throws BehaviourException {
		Vector3f result = new Vector3f(boid.getFeatures().getDirection());
		Quaternion q = new Quaternion();
		float deviation = Util.random(amplitudeMin, amplitudeMax);
		q = q.fromAngles(-deviation, deviation, deviation);
		q.multLocal(result);
		return result;
	}
}
